app.controller("recordPaymentController",function ($scope,$controller,$location,recordPaymentService, taxInfoService) {

    $controller("baseController",{$scope:$scope});

    //定义条件查询对象
    $scope.searchEntity = {"batchNumber":null};

    //获取打款记录列表
    $scope.findPage = function(pageNum,pageSize){

        if (pageNum == null) pageNum = 1;

        if (pageSize == null) pageSize = 10;

        if (startTime != null){
            $scope.searchEntity.startTime = startTime;
        }

        if (endTime != null){
            $scope.searchEntity.endTime = endTime;
        }

        $scope.findTaxInfoByBrandId()

        recordPaymentService.findPage(pageNum,pageSize,$scope.searchEntity).success(function (response) {

            if (response.code == 200){
                $scope.recordPaymentList = response.data;

                //更新总记录数
                $scope.paginationConf.totalItems=response.total;


            } else {
                alert(response.msg);
            }
        });

    };

    //重置条件查询参数
    $scope.resetSearchEntity = function(){

        $scope.searchEntity = {"batchNumber":null};

        $scope.reloadList();
    };

    //根据批次号查询订单明细
    $scope.findOneByBatchNumber = function(){

        //获取地址栏批次号
        var batchNumber = $location.search()['batchNumber'];

        if (batchNumber == null) return;

        //批次号
        $scope.searchEntity.batchNumber = batchNumber;


    };

    //监控订单状态变量
    $scope.$watch("searchEntity.orderStatus",function (newValue, oldValue) {

        if (newValue == null) return;

        $scope.reloadList();
    });

    //数字四舍五入 num-数字 digit-保留位数
    $scope.numParse = function (num,digit) {

        var s = num.toFixed(digit);

        return s;
    };
    
    //字符串格式化
    $scope.strParse = function (str) {

        if (str != null && str.indexOf("：") != -1) {
            str = str.substring(str.indexOf("：") + 1,str.length);
        }

        if (str != null && str.indexOf("(") != -1){
            str = str.split("(")[0];
        }

        if (str != null && str.indexOf("[") != -1){
            str = str.split("[")[0];
        }

        return str;
    };

    //导出功能
    $scope.download = function () {

        if (!confirm("您确定导出吗？"))  return;

        if (startTime != null){
            $scope.searchEntity.startTime = startTime;
        }

        if (endTime != null){
            $scope.searchEntity.endTime = endTime;
        }

        recordPaymentService.download($scope.searchEntity).success(function (response) {

          if (response.code == 200){

              // 文件下载
              window.open(response.msg);

              alert("下载完成");
          } else {
              alert(response.msg);
          }
        })
    };

    $scope.taxInfoList = []
    $scope.findTaxInfoByBrandId = function () {
        taxInfoService.findByBrandId().success(function (res) {
            $scope.taxInfoList = res.data;
        });
    };
});